using System;
using System.Windows;
using System.Windows.Data;

namespace ibba.src.sl.recursos.Converters
{
    public class BooleanToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Converter(value, parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Converter(value, parameter);
        }

        private Visibility Converter(object value, object parameter)
        {
            bool valor;
            
            if (value == null)
                valor = false;
            else
                valor = System.Convert.ToBoolean(value);


            if ((parameter != null) && (parameter.ToString().Equals("not", StringComparison.InvariantCultureIgnoreCase)
                                        || parameter.ToString().Equals("!", StringComparison.InvariantCultureIgnoreCase)))
            {
                valor = !valor;
            }

            return (valor ? Visibility.Visible : Visibility.Collapsed);
            
        }

        #endregion
    }
}
